package com.yonyou.pmclouds.job;

import java.util.Iterator;
import java.util.ServiceLoader;

public interface JobExecLogger {
    void log(String appendLogPattern, Object... appendLogArguments);

    void log(Throwable e);

    class Instance {
        private static volatile JobExecLogger logger;

        public static JobExecLogger getLogger() {
            if (logger == null) {
                synchronized (Instance.class) {
                    if (logger == null) {
                        ServiceLoader<JobExecLogger> services = ServiceLoader.load(JobExecLogger.class);
                        Iterator<JobExecLogger> it = services.iterator();
                        if (!it.hasNext()) {
                            throw new RuntimeException("there is no logger provided!");
                        }
                        logger = it.next();
                    }
                }
            }
            return logger;
        }
    }
}
